
#pragma once
#include "stdafx.h"
#include "soundEffectEditor/OcclusionXAPO.h"
//#define OCCLUSION_DEFAULT_LEVEL 49
//#define  OCCLUSION_MAX_LEVEL 99
//#define  OCCLUSION_MIN_LEVEL 1

class COcclusionDlg : public CDialogImpl<COcclusionDlg>, public CWinDataExchange<COcclusionDlg>
{
private:
	CTrackBarCtrl sliderOcclus;
	TCHAR strOcclus[20];
	OCCLUSION_PARAMETERS& Parameters;
	OCCLUSION_PARAMETERS CurrentParameters;

public:
	enum { IDD = IDD_OCCLUSION };

	COcclusionDlg(OCCLUSION_PARAMETERS& Param) : Parameters(Param) {} ;

	BEGIN_MSG_MAP(COcclusionDlg)
		MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
		COMMAND_ID_HANDLER(IDOK, OnOkCloseCmd)
		COMMAND_ID_HANDLER(IDCANCEL, OnCloseCmd)
		//MESSAGE_HANDLER(WM_HSCROLL, OnScroll)
		NOTIFY_HANDLER(IDC_SLIDER_OCCLUS, NM_CUSTOMDRAW, OnNMCustomDrawSliderOcclus)
	END_MSG_MAP()

	BEGIN_DDX_MAP()
		DDX_TEXT(IDC_EDIT_OCCLUS, strOcclus)
	END_DDX_MAP()

// Handler prototypes (uncomment arguments if needed):
//	LRESULT MessageHandler(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
//	LRESULT CommandHandler(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
//	LRESULT NotifyHandler(int /*idCtrl*/, LPNMHDR /*pnmh*/, BOOL& /*bHandled*/)

	LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
	{
		CenterWindow(GetParent());
		sliderOcclus.Attach(GetDlgItem(IDC_SLIDER_OCCLUS));
		sliderOcclus.SetRange( (int) (100 * OCCLUSION_MIN_LEVEL) , (int) ( 100 * OCCLUSION_MAX_LEVEL),  true);
		//sliderOcclus.SetPos(OCCLUSION_DEFAULT_LEVEL);
		if (Parameters.occlusionLevel >= OCCLUSION_MIN_LEVEL && Parameters.occlusionLevel <= OCCLUSION_MAX_LEVEL){
			sliderOcclus.SetPos((int)100 * (Parameters.occlusionLevel));
			CurrentParameters.occlusionLevel = Parameters.occlusionLevel;
		} else {
			sliderOcclus.SetPos((int)100 * OCCLUSION_DEFAULT_LEVEL);
			CurrentParameters.occlusionLevel = OCCLUSION_DEFAULT_LEVEL;
		}
		
		return TRUE;
	}

	LRESULT OnCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
	{
		EndDialog(wID);
		return 0;
	}

	LRESULT OnOkCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
	{
		Parameters = CurrentParameters;
		EndDialog(wID);
		return 0;
	}
	
	
	LRESULT OnNMCustomDrawSliderOcclus(int /*idCtrl*/, LPNMHDR pNMHDR, BOOL& /*bHandled*/)
	{		
		int nVal = sliderOcclus.GetPos();
		swprintf(strOcclus, L"%.2f", (float) nVal/100);
		DoDataExchange(DDX_LOAD, IDC_EDIT_OCCLUS);
		CurrentParameters.occlusionLevel = (float)nVal/100;
		return 0;
	}



};
